package com.sp.system.service.impl;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.sp.common.utils.DateUtils;
import com.sp.system.domain.SysParkingSpot;
import com.sp.system.service.ISysParkingSpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sp.system.mapper.SysVehicleMapper;
import com.sp.system.domain.SysVehicle;
import com.sp.system.service.ISysVehicleService;

/**
 * 车辆Service业务层处理
 *
 * 
 * @date 2024-11-24
 */
@Service
public class SysVehicleServiceImpl implements ISysVehicleService {
    @Autowired
    private SysVehicleMapper sysVehicleMapper;

    @Autowired
    private ISysParkingSpotService sysParkingSpotService;

    /**
     * 查询车辆
     *
     * @param id 车辆主键
     * @return 车辆
     */
    @Override
    public SysVehicle selectSysVehicleById(Long id) {
        return sysVehicleMapper.selectSysVehicleById(id);
    }

    /**
     * 查询车辆列表
     *
     * @param sysVehicle 车辆
     * @return 车辆
     */
    @Override
    public List<SysVehicle> selectSysVehicleList(SysVehicle sysVehicle) {
        return sysVehicleMapper.selectSysVehicleList(sysVehicle).stream()
                .peek(e -> e.setSysParkingSpot(
                        sysParkingSpotService.selectSysParkingSpotById(e.getParkingSpotId()))
                )
                .collect(Collectors.toList());
    }

    /**
     * 新增车辆
     *
     * @param sysVehicle 车辆
     * @return 结果
     */
    @Override
    public int insertSysVehicle(SysVehicle sysVehicle) {
        sysVehicle.setCreateTime(DateUtils.getNowDate());
        return sysVehicleMapper.insertSysVehicle(sysVehicle);
    }

    /**
     * 修改车辆
     *
     * @param sysVehicle 车辆
     * @return 结果
     */
    @Override
    public int updateSysVehicle(SysVehicle sysVehicle) {
        sysVehicle.setUpdateTime(DateUtils.getNowDate());
        return sysVehicleMapper.updateSysVehicle(sysVehicle);
    }

    /**
     * 批量删除车辆
     *
     * @param ids 需要删除的车辆主键
     * @return 结果
     */
    @Override
    public int deleteSysVehicleByIds(Long[] ids) {
        return sysVehicleMapper.deleteSysVehicleByIds(ids);
    }

    /**
     * 删除车辆信息
     *
     * @param id 车辆主键
     * @return 结果
     */
    @Override
    public int deleteSysVehicleById(Long id) {
        return sysVehicleMapper.deleteSysVehicleById(id);
    }
}
